<?php
namespace Common\Model;
use Think\Model;
class StudentModel extends Model {
    public $modelName = '学生';
    public $modelIcon = 'icon-user';
    public $notAuthority = true;
    public $excel = true;
    public $update = true;
    public $detail = true;
    public $delete = true;
    protected $_auto = [
        ['create_time', 'strtotime', 3, 'function'],
        ['update_time', 'strtotime', 3, 'function'],
        ['create_time', 'time', 1, 'function'],
        ['update_time', 'time', 2, 'function'],
    ];
    protected $_validate = [
        ['id', 'require', 'ID必须填写!'],
        ['class_id', 'require', '所属班级必须填写!'],
        ['name', 'require', '学生姓名必须填写!'],
        ['number', 'require', '学号必须填写!'],
        ['identity', 'require', '身份证必须填写!'],
        ['state', 'require', '状态必须填写!'],
        ['create_time', 'require', '创建时间必须填写!'],
        ['update_time', 'require', '更新时间必须填写!'],
    ];
    public $fieldMap = [
        'id'=>[
            'type'=>'input',
            'name'=>'ID',
            'list'=>true,
            'search'=>true,
            'input'=>false,
            'required'=>true,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'class_id'=>[
            'type'=>'foreign',
            'name'=>'所属班级',
            'list'=>true,
            'search'=>true,
            'input'=>true,
            'required'=>true,
            'detail'=>true,
            'excel'=>true,
            'content'=>'class,id,name,select',
            'search_specify'=>'  
            <div class="col-md-3 search-input-div">
                    <select name="searchMap[class_id]" id="class_id" class="width-100 search-select">
                        <option value="" class="search-select-default-option">所在班级</option>
                        <php>$foriegnModel = D("class")->select();</php>
                        <volist name="foriegnModel" id="vo">
                        <php>
                           $major=D("major")->where(["id"=>$vo["major_id"]])->find();
                           $grade=D("grade")->where(["id"=>$vo["grade_id"]])->find();
                        </php>
                        <option value="{$vo[\'id\']}" <if condition ="$searchMap[\'class_id\'] eq $vo[\'id\']"> selected </if>>{$grade["name"]}{$major["name"]}{$vo[\'name\']}</option>
                        </volist>
                    </select>
                </div>',
            'list_specify'=>'
            <php>
            $class=D("Class")->find($vo["class_id"]);
            $grade=D("Grade")->where(["id"=>$class["grade_id"]])->find();
            $major=D("Major")->where(["id"=>$class["major_id"]])->find();
            </php>
            <td class="center">
            {$grade["name"]}{$major["name"]}{$class["name"]}
            </td>
            ',
            'update_specify'=>'
            <div class="form-group">
                <label class="col-xs-12 col-sm-3 col-md-3 control-label no-padding-right" for="class_id"> 所属班级 </label>
                <div class="col-xs-12 col-sm-6">
                    <span class="block input-icon input-icon-right">
                        <select name="class_id" id="class_id" class="width-100" >
                            <php> $class = D("Class")->select(); </php>
                            <volist name="class" id="vo">
                                <php>
                                    $grade=D("Grade")->find($vo["grade_id"]);
                                    $major=D("Major")->find($vo["major_id"]);
                                </php>
                            <option value="{$vo["id"]}" <if condition ="$model[\'class_id\'] eq $vo[\'id\']"> selected </if>>{$grade["name"]}{$major["name"]}{$vo["name"]}</option>
                            </volist>
                        </select>
                        <i class=""></i>
                    </span>
                </div>
                <div class="help-block col-xs-12 col-sm-reset inline" style="margin-bottom: 5px;"></div>
             </div>

            ',
            'detail_specify'=>'',
            'export_specify'=>'
              $class=D("class")->where(["id"=>$value])->find();
              $grade=D("grade")->where(["id"=>$class["grade_id"]])->find();
              $major=D("major")->where(["id"=>$class["major_id"]])->find();
              return $grade["name"].$major["name"].$class["name"];
            ',
        ],
        'name'=>[
            'type'=>'input',
            'name'=>'学生姓名',
            'list'=>true,
            'search'=>true,
            'input'=>true,
            'required'=>false,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'number'=>[
            'type'=>'input',
            'name'=>'学号',
            'list'=>true,
            'search'=>true,
            'input'=>false,
            'required'=>false,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>false,
            'detail_specify'=>'',
        ],
        'sex'=>[
            'type'=>'select',
            'name'=>'性别',
            'list'=>true,
            'search'=>false,
            'input'=>true,
            'required'=>false,
            'detail'=>true,
            'excel'=>true,
            'content'=>'男,女',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'age'=>[
            'type'=>'input',
            'name'=>'年龄',
            'list'=>true,
            'search'=>false,
            'input'=>true,
            'required'=>false,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'site'=>[
            'type'=>'input',
            'name'=>'地址',
            'list'=>true,
            'search'=>false,
            'input'=>true,
            'required'=>false,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'identity'=>[
            'type'=>'input',
            'name'=>'身份证',
            'list'=>true,
            'search'=>true,
            'input'=>true,
            'required'=>true,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
            'export_specify'=>'
              return "\'".$value;
            ',
        ],
        'remark'=>[
            'type'=>'input',
            'name'=>'备注',
            'list'=>true,
            'search'=>false,
            'input'=>true,
            'required'=>false,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'state'=>[
            'type'=>'select',
            'name'=>'状态',
            'list'=>true,
            'search'=>true,
            'input'=>true,
            'required'=>true,
            'detail'=>true,
            'excel'=>true,
            'content'=>'正常,转学,休学,退学',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'create_time'=>[
            'type'=>'datetime',
            'name'=>'创建时间',
            'list'=>false,
            'search'=>false,
            'input'=>false,
            'required'=>true,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
        'update_time'=>[
            'type'=>'datetime',
            'name'=>'更新时间',
            'list'=>false,
            'search'=>false,
            'input'=>false,
            'required'=>true,
            'detail'=>true,
            'excel'=>true,
            'content'=>'',
            'list_specify'=>'',
            'update_specify'=>'',
            'detail_specify'=>'',
        ],
    ];
}
